package cn.lili.modules.order.order.entity.dto;

import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.order.order.entity.enums.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotEmpty;

@EqualsAndHashCode(callSuper = true)
@Data
public class OrderClerkSearchParams extends PageVO {

    private static final long serialVersionUID = -6380573339039959194L;


    @NotEmpty(message = "页面标签不能为空")
    @ApiModelProperty(value = "页面标签", required = true,
            example = "DATING:全部," +
                    "MY_ALL:我的全部任务," +
                    "MY_DELIVERED:配货," +
                    "MY_ENTRUCKED:装车," +
                    "MY_COMPLETE:已完成")
    private String tag;

    @NotEmpty(message = "店铺ID不能为空")
    @ApiModelProperty(value = "店铺ID", required = true)
    private String storeId;

    @ApiModelProperty(value = "员工ID")
    private String clerkId;

    public <T> QueryWrapper<T> queryWrapper() {
        QueryWrapper<T> wrapper = new QueryWrapper<>();
        //按标签查询
        if (CharSequenceUtil.isNotEmpty(tag)) {
            String orderStatusColumn = "o.order_status";
            String clerkColumn = "o.clerk_id";
            switch (tag) {
                //大厅待分配订单
                case "DATING":
                    wrapper.eq(orderStatusColumn, OrderStatusEnum.PAID.name()).isNull(clerkColumn);
                    break;
                //我的任务 全部
                case "MY_ALL":
                    wrapper.and(statusWrapper -> statusWrapper.eq(orderStatusColumn, OrderStatusEnum.UNDELIVERED.name()).or().eq(orderStatusColumn, OrderStatusEnum.UNENTRUCKED.name())).like(clerkColumn,clerkId);
                    break;
                //我的任务 配货
                case "MY_DELIVERED":
                    wrapper.and(statusWrapper -> statusWrapper.eq(orderStatusColumn, OrderStatusEnum.UNDELIVERED.name())).like(clerkColumn,clerkId);
                    break;
                //已取消
                case "MY_ENTRUCKED":
                    wrapper.and(statusWrapper -> statusWrapper.eq(orderStatusColumn, OrderStatusEnum.UNENTRUCKED.name()).or().eq(orderStatusColumn, OrderStatusEnum.UNCALLED.name()).or().eq(orderStatusColumn, OrderStatusEnum.CALLED.name())).like(clerkColumn,clerkId);
                    break;
                //已完成
                case "MY_COMPLETE":
                    wrapper.and(statusWrapper -> statusWrapper.eq(orderStatusColumn, OrderStatusEnum.ENTRUCKED.name()).or().eq(orderStatusColumn, OrderStatusEnum.COMPLETED.name())).like(clerkColumn,clerkId);
                    break;
                default:
                    break;
            }
        }
        wrapper.eq("o.store_id", storeId);
        wrapper.eq("o.delete_flag", false);
        wrapper.orderByDesc("o.delivery_time","o.create_time");
        return wrapper;
    }

}

